<?php
class Default_Model_Like extends Zend_Db_Table{

	protected $_name = LIKE_TABLE;
	protected $_primary = 'like_id';

	private $LIKE_ID = 'like_id';
	private $LOCATION_ID = 'location_id';
	private $PHOTO_ID = 'photo_id';
	private $USER_ID = 'user_id';

	protected $db;

	public function __construct(){
		//Goi ket noi voi Zend Db
		$this->db = Zend_Registry::get('connectDB');
	}

	protected $_messageError = null;

	
	public function getLikeByLocId($locId) {
		$select = $this->db->select()->from(LIKE_TABLE)->where($this->LOCATION_ID.' = ?',$locId);
		$result  = $this->db->fetchAll($select);
		return $result;
	}
	
	public function getLikeByPhotoId($photoId) {
		$select = $this->db->select()->from(LIKE_TABLE)->where($this->PHOTO_ID.' = ?',$photoId);
		$result  = $this->db->fetchAll($select);
		return $result;
	}

	
	// Xoa like
	public function deleteLikeByLocId($locId){
		try {
			$this->db->delete(LIKE_TABLE,$this->LOCATION_ID.' = ' . $locId);
			return true;
		} catch (Exception $e) {
			$this->_messageError = $e->getMessage();
			return false;
		}
	}
	public function deleteLikeByPhotoId($photoId){
		try {
			$this->db->delete(LIKE_TABLE,$this->PHOTO_ID.' = ' . $photoId);
			return true;
		} catch (Exception $e) {
			$this->_messageError = $e->getMessage();
			return false;
		}
	}
	public function deleteLikeByUserId($userId){
		try {
			$this->db->delete(LIKE_TABLE,$this->USER_ID.' = ' . $userId);
			return true;
		} catch (Exception $e) {
			$this->_messageError = $e->getMessage();
			return false;
		}
	}

	public function getError(){
		return $this->_messageError;
	}
}